function t(t, a, i) {
    return a in t ? Object.defineProperty(t, a, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = i, t;
}

var a = getApp(), i = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js"), e = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js"), r = require("../../E99BC573A71FB5DF8FFDAD745E5CA4D1.js");

Component({
    properties: {
        from: {
            type: String,
            value: "tabbar"
        }
    },
    data: {
        icon: {
            0: "../../assets/images/cart_not_selected.png",
            1: "../../assets/images/cart_selected.png"
        },
        isLogin: !1,
        isLogining: !1,
        winWidth: a.globalData.windowWidth,
        winHeight: a.globalData.windowHeight,
        screenHeight: a.globalData.screenHeight,
        statusBarHeight: a.globalData.statusBarHeight,
        titleBarHeight: a.globalData.titleBarHeight,
        attrAnimData: {},
        defaultData: {},
        skuData: [],
        color: 1,
        clothing: 1,
        skuKeyData: [],
        clothingSrc: {},
        isMutipleSize: !1,
        curEditId: null,
        curSpecId: "",
        curEditItem: {},
        curAttr: {},
        curAttrText: {},
        attrList: [],
        attrLen: {},
        attrKeys: {},
        skuResult: {},
        cantSelectedItems: {},
        sizeData: {},
        initTeamSizeData: JSON.stringify({}),
        teamSizeData: {},
        curSizeData: {},
        colorObj: {},
        clothImgObj: {},
        productPrice: 0,
        cartData: {
            list: null,
            isEdit: !1,
            selectedList: [],
            isSelectedAll: !1,
            selectedTotal: 0,
            totalPrice: 0,
            total: 0,
            totalShirt: 0,
            page: 1,
            isFirstLoading: !0
        }
    },
    lifetimes: {
        ready: function() {
            this.attrAnim = wx.createAnimation({
                duration: 200,
                timingFunction: "ease-in"
            });
        }
    },
    pageLifetimes: {
        show: function() {
            null !== e._cb && (this.setData({
                isLogining: !1
            }), e._cb = null), this.init();
        },
        hide: function() {
            this.hideAttrBox();
        }
    },
    methods: {
        pullDownRefresh: function() {
            a.globalData.isLogin ? this.getCartData({
                page: 1,
                refresh: "down"
            }) : wx.stopPullDownRefresh();
        },
        reachBottom: function() {
            var t = this.data.cartData;
            a.globalData.isLogin && t.total !== t.list.length && this.getCartData({
                page: this.data.cartData.page + 1
            });
        },
        unload: function() {
            this.hideAttrBox();
        },
        init: function() {
            var t = this, i = a.globalData.isLogin, e = a.globalData.cartPageData, r = e.isFirstLoading;
            r && (e.isFirstLoading = !1, a.globalData.cartPageData = e), this.setData({
                cartData: e,
                isLogin: i,
                skuData: a.globalData.productSkuData || []
            }, function() {
                i && a.globalData.isNeedToUpdateCartData && (a.globalData.isNeedToUpdateCartData = !1, 
                t.getCartData({
                    page: 1,
                    loading: r
                }));
            });
        },
        setCartData: function(t) {
            var i = this, e = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1];
            a.globalData.cartPageData = t, this.setData({
                cartData: t
            }, function() {
                e && i.setSelectedData();
            });
        },
        getCartData: function(t) {
            var e = this, r = t.page, o = void 0 === r ? 1 : r, n = t.loading, s = void 0 !== n && n, l = t.refresh, d = void 0 === l ? "none" : l;
            s && wx.showLoading({
                title: "加载中...",
                mask: !0
            }), i.get("/v2/shopping/list", {
                page: o
            }).then(function(t) {
                if (s && wx.hideLoading(), "down" === d && wx.stopPullDownRefresh(), 1001 === t.data.code) {
                    var i = t.data.response, r = e.data.cartData, n = r.list;
                    r.total = i.total;
                    var l = i.data.map(function(t) {
                        return t.selected = !1, t;
                    });
                    n = 1 === o ? l : n.concat(l), r.page = o, r.list = n, r = a.globalData.cartData = Object.assign(r), 
                    e.setCartData(r);
                }
            }).catch(function() {
                s && wx.hideLoading(), "down" === d && wx.stopPullDownRefresh();
            });
        },
        setSelectItem: function(t) {
            for (var a = 1 * t.currentTarget.dataset.id, i = this.data.cartData, e = i.list, r = 0; r < e.length; r++) if (a === e[r].id) {
                e[r].selected = !e[r].selected, i = Object.assign(i, {
                    list: e
                }), this.setCartData(i);
                break;
            }
        },
        setSelectedData: function() {
            var t = this.data.cartData, a = t.list, i = [], e = 0, r = 0, o = 0, n = 0, s = t.isEdit, l = !0, d = !1, c = void 0;
            try {
                for (var u, h = a[Symbol.iterator](); !(l = (u = h.next()).done); l = !0) {
                    var g = u.value;
                    e += 1 * g.goods_num, 1 === g.cart_type && (n += 1), g.selected && (s ? (o += 1 * g.goods_num, 
                    r += 1 * g.total_fee_cent, i.push(g)) : 1 === g.cart_type ? (o += 1 * g.goods_num, 
                    r += 1 * g.total_fee_cent, i.push(g)) : g.selected = !1);
                }
            } catch (t) {
                d = !0, c = t;
            } finally {
                try {
                    !l && h.return && h.return();
                } finally {
                    if (d) throw c;
                }
            }
            t = Object.assign(t, {
                selectedList: i,
                totalShirt: e,
                selectedTotal: o,
                totalPrice: r,
                isSelectedAll: i.length === (s ? a.length : n)
            }), this.setCartData(t, !1);
        },
        setIsSelected: function() {
            var t = this.data.cartData, a = t.isEdit, i = t.list, e = !t.isSelectedAll;
            i = i.map(function(t) {
                return t.selected = e, !a && e && 2 === t.cart_type && (t.selected = !1), t;
            }), t = Object.assign(t, {
                list: i,
                isSelectedAll: e
            }), this.setCartData(t);
        },
        handleEdit: function() {
            var t = this.data.cartData;
            t.isEdit = !t.isEdit, this.setCartData(t);
        },
        handleDel: function() {
            var t = this;
            this.data.cartData.selectedList.length ? wx.showModal({
                title: "操作提示",
                content: "您确定删除选择的商品吗？",
                cancelText: "删除",
                cancelColor: "#FF2121",
                confirmText: "取消",
                confirmColor: "#000000",
                success: function(a) {
                    a.cancel && t.deleteProduct();
                }
            }) : wx.showToast({
                title: "请选择要删除的商品！",
                icon: "none"
            });
        },
        deleteProduct: function() {
            var t = this;
            wx.showLoading({
                title: "正在删除...",
                mask: !0
            });
            var a = [], e = this.data.cartData.selectedList, r = !0, o = !1, n = void 0;
            try {
                for (var s, l = e[Symbol.iterator](); !(r = (s = l.next()).done); r = !0) {
                    var d = s.value;
                    a.push(d.id);
                }
            } catch (t) {
                o = !0, n = t;
            } finally {
                try {
                    !r && l.return && l.return();
                } finally {
                    if (o) throw n;
                }
            }
            i.delete("/v2/shopping/delete", {
                id: a.join(",")
            }).then(function(a) {
                if (wx.hideLoading(), 1001 === a.data.code) {
                    var i = t.data.cartData;
                    i.selectedList = [], t.setCartData(i, !1), t.getCartData({
                        page: 1,
                        loading: !0
                    });
                }
            }).catch(function() {
                wx.hideLoading();
            });
        },
        login: function() {
            var t = this;
            this.data.isLogin || this.data.isLogining || this.setData({
                isLogining: !0
            }, function() {
                e.login(function() {
                    wx.hideLoading(), t.setData({
                        isLogining: !1
                    });
                });
            });
        },
        submit: function() {
            var t = this.data.cartData.selectedList, a = t.length;
            if (a) {
                if (a > 1) {
                    var i = t[0].status, e = !0, r = !1, o = void 0;
                    try {
                        for (var n, s = t[Symbol.iterator](); !(e = (n = s.next()).done); e = !0) if (n.value.status !== i) return void wx.showToast({
                            icon: "none",
                            title: "普通作品不可以和团购作品一起结算，请重新选择！",
                            duration: 2500
                        });
                    } catch (t) {
                        r = !0, o = t;
                    } finally {
                        try {
                            !e && s.return && s.return();
                        } finally {
                            if (r) throw o;
                        }
                    }
                }
                var l = [], d = !0, c = !1, u = void 0;
                try {
                    for (var h, g = t[Symbol.iterator](); !(d = (h = g.next()).done); d = !0) {
                        var f = h.value;
                        l.push(f.id);
                    }
                } catch (t) {
                    c = !0, u = t;
                } finally {
                    try {
                        !d && g.return && g.return();
                    } finally {
                        if (c) throw u;
                    }
                }
                wx.navigateTo({
                    url: "/pages/order/order?from=cart&cartId=" + l.join(",")
                });
            } else wx.showToast({
                title: "请选择要结算的商品！",
                icon: "none"
            });
        },
        handleEditItem: function(t) {
            var i = this, e = 1 * t.currentTarget.dataset.id, r = t.currentTarget.dataset.specId, o = this.data.cartData.list, n = {}, s = !0, l = !1, d = void 0;
            try {
                for (var c, u = o[Symbol.iterator](); !(s = (c = u.next()).done); s = !0) {
                    var h = c.value;
                    if (h.id === e) {
                        n = JSON.parse(JSON.stringify(h));
                        break;
                    }
                }
            } catch (t) {
                l = !0, d = t;
            } finally {
                try {
                    !s && u.return && u.return();
                } finally {
                    if (l) throw d;
                }
            }
            this.setData({
                curSpecId: r,
                curEditId: e,
                curEditItem: n,
                clothing: n.goods_id
            }, function() {
                var t = a.globalData.defaultClothingData;
                t ? i.setDefaultData(t) : i.getDefaultData();
            });
        },
        setDefaultData: function(t) {
            var a = this, i = {}, e = {}, r = !0, o = !1, n = void 0;
            try {
                for (var s, l = t[Symbol.iterator](); !(r = (s = l.next()).done); r = !0) {
                    var d = s.value, c = {};
                    e[d.id] = d.goods_spec[0].positive_picture.thumb;
                    for (var u = 0; u < d.goods_spec.length; u++) {
                        var h = d.goods_spec[u];
                        if (h.idx = u, c[h.color_id] = h, !i[h.color_id]) {
                            var g = {
                                id: h.color_id,
                                value: h.color_value
                            };
                            i[h.color_id] = g;
                        }
                    }
                }
            } catch (t) {
                o = !0, n = t;
            } finally {
                try {
                    !r && l.return && l.return();
                } finally {
                    if (o) throw n;
                }
            }
            this.setData({
                defaultData: t,
                colorObj: i,
                clothImgObj: e
            }, function() {
                a.getSkuData();
            });
        },
        getDefaultData: function() {
            var t = this;
            wx.showLoading({
                mask: !0,
                title: "加载中..."
            }), i.get("/v2/goods").then(function(i) {
                if (wx.hideLoading(), 1001 === i.data.code) {
                    var e = i.data.response.data;
                    a.globalData.defaultClothingData = e, t.setDefaultData(e);
                }
            }).catch(function() {
                wx.hideLoading();
            });
        },
        getSkuData: function() {
            var t = this, e = this.data.skuData;
            e && e.length ? (this.getSkuResult(), this.showAttrBox()) : (wx.showLoading({
                title: "加载中...",
                mask: !0
            }), i.get("/v2/productAttribute").then(function(i) {
                if (wx.hideLoading(), 1001 === i.data.code) {
                    var e = i.data.response.data;
                    a.globalData.productSkuData = e, t.setData({
                        skuData: e
                    }, function() {
                        t.getSkuResult(), t.showAttrBox();
                    });
                }
            }).catch(function() {
                wx.hideLoading();
            }));
        },
        getSkuResult: function() {
            var t = this, a = this.data.skuData;
            if (a && a.length) {
                var i = this.data.curEditItem, e = r.getSkuResult(a, i.goods.print_position), o = e.skuResult, n = e.skuKeyData, s = {}, l = [], d = {}, c = {}, u = !0, h = !1, g = void 0;
                try {
                    for (var f, v = n[Symbol.iterator](); !(u = (f = v.next()).done); u = !0) {
                        var y = f.value;
                        l.push(y.type), c[y.type] = y.attr.length, "clothing" === y.type ? s[y.type] = this.data.clothing : s[y.type] = null;
                        var D = !0, p = !1, m = void 0;
                        try {
                            for (var S, _ = y.attr[Symbol.iterator](); !(D = (S = _.next()).done); D = !0) {
                                var w = S.value;
                                d[y.type + "/" + w.id] = w;
                            }
                        } catch (t) {
                            p = !0, m = t;
                        } finally {
                            try {
                                !D && _.return && _.return();
                            } finally {
                                if (p) throw m;
                            }
                        }
                    }
                } catch (t) {
                    h = !0, g = t;
                } finally {
                    try {
                        !u && v.return && v.return();
                    } finally {
                        if (h) throw g;
                    }
                }
                o = r.initSKU(o, l, "/"), this.setData({
                    skuResult: o,
                    skuKeyData: n,
                    curAttr: s,
                    attrList: l,
                    attrLen: c,
                    attrKeys: d
                }, function() {
                    t.getSizeData();
                });
            }
        },
        getSizeData: function() {
            var a = this, i = this.data.skuData;
            if (i && i.length) {
                var e = {}, r = {}, o = !0, n = !1, s = void 0;
                try {
                    for (var l, d = i[Symbol.iterator](); !(o = (l = d.next()).done); o = !0) {
                        var c = l.value;
                        if (!e[c.goods_list.id] || e[c.goods_list.id] && !e[c.goods_list.id][c.size_list.id]) {
                            var u = JSON.parse(JSON.stringify(c.size_list));
                            u.quantity = 0, e[c.goods_list.id] = Object.assign(e[c.goods_list.id] || {}, t({}, c.size_list.id, u));
                        }
                        var h = JSON.parse(JSON.stringify(c.size_list));
                        h.quantity = 0;
                        var g = c.goods_id + "_" + c.color_id + "_" + c.style_id;
                        r[g] ? r[g][h.id] = h : r[g] = t({}, h.id, h);
                    }
                } catch (t) {
                    n = !0, s = t;
                } finally {
                    try {
                        !o && d.return && d.return();
                    } finally {
                        if (n) throw s;
                    }
                }
                this.setData({
                    sizeData: e,
                    initSizeData: JSON.stringify(e),
                    teamSizeData: r,
                    initTeamSizeData: JSON.stringify(r)
                }, function() {
                    a.getEditGoodsData();
                });
            }
        },
        getEditGoodsData: function() {
            var t = this, a = this.data.curSpecId.split(","), i = this.data.skuData, e = this.data.curEditItem, r = this.data.teamSizeData, o = e.product_size, n = null, s = null, l = this.data.curAttr, d = !0, c = !1, u = void 0;
            try {
                for (var h, g = i[Symbol.iterator](); !(d = (h = g.next()).done); d = !0) {
                    var f = h.value, v = !0, y = !1, D = void 0;
                    try {
                        for (var p, m = a[Symbol.iterator](); !(v = (p = m.next()).done); v = !0) {
                            var S = p.value;
                            if (f.id === 1 * S) {
                                r[f.goods_list.id + "_" + f.color_list.id + "_" + f.style_list.id][f.size_list.id].quantity = o[f.size_list.name], 
                                n = f.color_list.id, s = f.style_list.id;
                                break;
                            }
                        }
                    } catch (t) {
                        y = !0, D = t;
                    } finally {
                        try {
                            !v && m.return && m.return();
                        } finally {
                            if (y) throw D;
                        }
                    }
                }
            } catch (t) {
                c = !0, u = t;
            } finally {
                try {
                    !d && g.return && g.return();
                } finally {
                    if (c) throw u;
                }
            }
            l.color = n, l.type = s, this.setData({
                teamSizeData: r,
                color: n,
                curAttr: l
            }, function() {
                t.getCantSelectedItems(), t.fillShirtAttr();
            });
        },
        getCantSelectedItems: function() {
            var t = this, a = this.data, i = a.curAttr, e = a.attrList, o = a.attrKeys, n = a.skuResult;
            this.setData(r.getCantSelectedItems(i, e, o, n), function() {
                return t.changeProductPrice();
            });
        },
        fillShirtAttr: function() {
            var t = this, a = this.data, i = a.skuKeyData, e = a.curAttr, r = "", o = {}, n = {}, s = !0, l = !1, d = void 0;
            try {
                for (var c, u = i[Symbol.iterator](); !(s = (c = u.next()).done); s = !0) {
                    var h = c.value, g = !0, f = !1, v = void 0;
                    try {
                        for (var y, D = h.attr[Symbol.iterator](); !(g = (y = D.next()).done); g = !0) {
                            var p = y.value;
                            if (1 * p.id == 1 * e[h.type]) {
                                "size" === h.type && (o = p), "size" !== h.type && (r += p.name + ",", n[h.type] = p.name);
                                break;
                            }
                        }
                    } catch (t) {
                        f = !0, v = t;
                    } finally {
                        try {
                            !g && D.return && D.return();
                        } finally {
                            if (f) throw v;
                        }
                    }
                }
            } catch (t) {
                l = !0, d = t;
            } finally {
                try {
                    !s && u.return && u.return();
                } finally {
                    if (l) throw d;
                }
            }
            this.setData({
                productAttr: r.length > 0 ? r.slice(0, -1) : "",
                curSizeData: o,
                curAttrText: n
            }, function() {
                t.getClothingSrc();
            });
        },
        getClothingSrc: function() {
            var t = this.data.defaultData, a = this.data.color, i = this.data.clothing, e = {}, r = !0, o = !1, n = void 0;
            try {
                for (var s, l = t[Symbol.iterator](); !(r = (s = l.next()).done); r = !0) {
                    var d = s.value;
                    if (1 * d.id == 1 * i) if (a) {
                        var c = !0, u = !1, h = void 0;
                        try {
                            for (var g, f = d.goods_spec[Symbol.iterator](); !(c = (g = f.next()).done); c = !0) {
                                var v = g.value;
                                if (1 * v.color_id == 1 * a) {
                                    e = {
                                        1: v.positive_picture,
                                        2: v.opposite_picture
                                    };
                                    break;
                                }
                            }
                        } catch (t) {
                            u = !0, h = t;
                        } finally {
                            try {
                                !c && f.return && f.return();
                            } finally {
                                if (u) throw h;
                            }
                        }
                    } else e = {
                        1: d.goods_spec[0].positive_picture,
                        2: d.goods_spec[0].opposite_picture
                    };
                    if (e[1]) break;
                }
            } catch (t) {
                o = !0, n = t;
            } finally {
                try {
                    !r && l.return && l.return();
                } finally {
                    if (o) throw n;
                }
            }
            this.setData({
                clothingSrc: e
            });
        },
        changeShirtAttr: function(t) {
            var a = this, i = t.currentTarget.dataset, e = i.id, r = i.type;
            e *= 1;
            var o = this.data.curAttr, n = this.data.attrLen, s = {};
            if ("clothing" === r && o[r] !== e) {
                s.teamSizeData = JSON.parse(this.data.initTeamSizeData);
                for (var l in n) "clothing" !== l && "size" !== l && n[l] > 1 && (o[l] = null);
            }
            o[r] !== e && (o[r] = e), s.curAttr = o, "clothing" === r ? s.clothing = e : "color" === r && (s.color = e), 
            this.setData(s, function() {
                a.getCantSelectedItems(), a.fillShirtAttr();
            });
        },
        getIsCanSubmit: function() {
            var t = this.data.curAttr, a = !0;
            for (var i in t) if ("size" !== i && !t[i]) {
                a = !1;
                break;
            }
            return a;
        },
        changeProductPrice: function() {
            var t = this.data, a = t.attrList, i = t.curAttr, e = t.skuResult, r = t.curEditItem, o = [], n = !0, s = !1, l = void 0;
            try {
                for (var d, c = a[Symbol.iterator](); !(n = (d = c.next()).done); n = !0) {
                    var u = d.value;
                    for (var h in i) if (i[h] && h === u) {
                        o.push(h + "/" + i[h]);
                        break;
                    }
                }
            } catch (t) {
                s = !0, l = t;
            } finally {
                try {
                    !n && c.return && c.return();
                } finally {
                    if (s) throw l;
                }
            }
            var g = [];
            e[o = o.join(",")] && (g = e[o].prices);
            var f = 0, v = 0, y = g.length;
            y > 0 && (v = g[0], f = g[y - 1]);
            var D = 100 * r.product_price_pattern_cent || 0;
            this.setData({
                productPrice: v === f ? (v + D) / 100 : (v + D) / 100 + "~" + (f + D) / 100
            });
        },
        lookShirtSize: function() {
            wx.navigateTo({
                url: "/pages/shirt/shirtSize"
            });
        },
        bindInputTeamNumblur: function(t) {
            var a = 1 * t.detail.value, i = t.target.dataset.id, e = this.data.teamSizeData, r = this.data.curAttr;
            a || (a = 0), e[r.clothing + "_" + r.color + "_" + r.type][i].quantity = a, this.setData({
                teamSizeData: e
            });
        },
        bindInputTeamNumClick: function() {
            wx.showToast({
                title: "请先选择上面衣服的属性",
                icon: "none"
            });
        },
        handleTeamNum: function(t) {
            var a = t.currentTarget.dataset.type, i = t.currentTarget.dataset.id, e = this.data.teamSizeData, r = this.data.curAttr, o = r.clothing + "_" + r.color + "_" + r.type, n = e[o][i].quantity;
            if ("add" === a) n += 1; else {
                if (0 === n) return;
                n -= 1;
            }
            e[o][i].quantity = n, this.setData({
                teamSizeData: e
            });
        },
        updateCartData: function() {
            var t = this;
            if (this.getIsCanSubmit()) {
                var a = this.data.curAttr, e = this.data.curAttrText, r = this.data.teamSizeData[a.clothing + "_" + a.color + "_" + a.type], o = {
                    id: this.data.curEditItem.id,
                    product_id: this.data.curEditId,
                    goods_id: a.clothing,
                    goods_spec_id: this.getGoodsSpecId(a, r)
                }, n = {};
                for (var s in r) {
                    var l = r[s];
                    l.quantity > 0 && (n[l.name] = l.quantity);
                }
                o.product_size = JSON.stringify(n);
                for (var d in e) "size" !== d && (o["product_" + d] = e[d]);
                wx.showLoading({
                    title: "提交修改中..."
                }), i.post("/v2/shopping/update", o).then(function(a) {
                    wx.hideLoading(), 1001 === a.data.code && (t.hideAttrBox(), wx.showToast({
                        title: "修改成功"
                    }), t.getCartData({
                        page: 1,
                        loading: !0
                    }));
                }).catch(function() {
                    wx.hideLoading();
                });
            } else wx.showToast({
                title: "请先选择衣服规格",
                icon: "none"
            });
        },
        getGoodsSpecId: function(t, a) {
            var i = this.data.skuData, e = [], r = !0, o = !1, n = void 0;
            try {
                for (var s, l = i[Symbol.iterator](); !(r = (s = l.next()).done); r = !0) {
                    var d = s.value;
                    for (var c in a) if (1 * d.goods_id == 1 * t.clothing && 1 * d.color_id == 1 * t.color && 1 * d.style_id == 1 * t.type && 1 * d.size_id === a[c].id && a[c].quantity > 0) {
                        e.push(d.id);
                        break;
                    }
                }
            } catch (t) {
                o = !0, n = t;
            } finally {
                try {
                    !r && l.return && l.return();
                } finally {
                    if (o) throw n;
                }
            }
            return e.join(",");
        },
        hideAttrBox: function() {
            this.handleAttrAnim(!1);
        },
        showAttrBox: function() {
            this.handleAttrAnim(!0);
        },
        handleAttrAnim: function(t) {
            var a = 0;
            t || (a = this.data.screenHeight), this.attrAnim.top(a).step(), this.setData({
                attrAnimData: this.attrAnim.export()
            });
        }
    }
});